home *** CD-ROM | disk | FTP | other *** search
- Path: news.ust.hk!eg_spm
- From: eg_spm@uxmail.ust.hk (She Pei Man James)
- Newsgroups: comp.lang.c
- Subject: Re: RETURN ();
- Date: 9 Feb 1996 02:43:12 GMT
- Organization: The Hong Kong University of Science and Technology
- Message-ID: <4fecc0$5os@news.ust.hk>
- References: <DMFxxq.7M7@emi.net>
- NNTP-Posting-Host: ustsu26.ust.hk
- X-Newsreader: TIN [version 1.2 PL2]
-
- samstar@emi.net wrote:
- : Is there a way to return muliple values to main from a seperate function ?
-
- : ex :
-
- : int main(void)
- : {
- : Input_data();
- : printf("Here all the input data");
- :
- : return 0;
- : }
-
- : int Input_data()
- : {
- : x=5,y=30,z=10 /* These were gotten by asking questions */
- : /* using printf / scanf/fgets (what ever) */
- : /*point is they are gotten by question */
-
- : return(x,y,z);
- : }
-
- : how will main be able to see these values ?
-
- : I tried this in main didn't help :
-
- : int main(x,y,z)
- : {
- : ect...
- : }
-
- : if anyone can help... please email me at samstar@emi.net
-
-
- : thanks....
-
- : samstar
- ya...i think it's better to manipulate this case by the command "struct"
- e.g. struct numbers { /* This is a delcaration of structure...
- int x; and "numbers" a the structure name defined
- int y; by u...and x,y,z is the elements in this
- int z; structure */
- }
-
- void main() { /* declare main with the type of "numbers"
-
- numbers XYZ; declare a variable XYZ in this type also.
-
- Input_data(XYZ); Using function Input_data to assign value
- to x, y, z.
- printf(XYZ.x,XYZ.y,
- XYZ.z) diaplay values of x,y,z
-
- numbers Input_data(numbers XYZ) { /* declare the return type as
- XYZ.x=1; "numbers" also and the input
- XYZ.y=2; parameter as "numbers" type
- XYZ.z=3; /* assign values to specified
- return XYZ; elements and then return them
- } through a struct. (numbers)
- }
- as i am using C++ in usual so may be there are some syntax error
- however i can sure that the function of structure in C and C++ are the
- same and this alroigthm would be work!
- for more detail ...u may try to refer some book of structure this command!
- hope this help!
- James
-
- --
- ======= The Hong Kong University of Science and Technology =======
- --- Computer Engineering ---
- [│\ÑAñσ] PeiMan. eg_spm@stu.ust.hk
- Pager: 71714141 csjames@ug.cs.ust.hk
- http://susis.ust.hk/~spmjames spmjames@susis.ust.hk
-